package xcu.lxj.nettychat.chat.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import xcu.lxj.nettychat.chat.domain.entity.RoomGroup;
import xcu.lxj.nettychat.chat.mapper.RoomGroupMapper;
import xcu.lxj.nettychat.common.domain.vo.request.CursorPageBaseReq;
import xcu.lxj.nettychat.common.domain.vo.response.CursorPageBaseResp;
import xcu.lxj.nettychat.common.utils.CursorUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author XinJian Lei
 * @Date 2024/9/29 10:50
 * @Version 1.0
 */
@Service
public class RoomGroupDao extends ServiceImpl<RoomGroupMapper, RoomGroup> {


    /**
     * 获取单个
     * @param roomId
     * @return
     */
    public RoomGroup getByRoomId(Long roomId) {
        return lambdaQuery()
                .eq(RoomGroup::getRoomId,roomId)
                .one();
    }

    /**
     * 获取房间列表
     * @param roomIds
     * @return
     */
    public List<RoomGroup> listByRoomIds(List<Long> roomIds) {
        if(roomIds == null)
            return Collections.emptyList();
        List<RoomGroup> list = lambdaQuery()
                .in(RoomGroup::getRoomId, roomIds)
                .list();

        return list;
    }
    public  Map<Long,RoomGroup> getBatch(List<Long> roomIds){
        List<RoomGroup> list = listByRoomIds(roomIds);
        Map<Long, RoomGroup> collect = list.stream().collect(Collectors.toMap(RoomGroup::getRoomId, roomGroup -> roomGroup));
        return  collect;
    }


    public CursorPageBaseResp<RoomGroup> getRoomGroupCursorPage(CursorPageBaseReq request,List<Long> groupIdList){

        return CursorUtils.getCursorPageByMysql(this,request,wrapper->{
            wrapper.in(RoomGroup::getId,groupIdList);
        },RoomGroup::getId);

    }
}
